﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class CX_XYTJControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        DropDownList DropDownList1, DropDownList2;
        MPCalendar Calendar1, Calendar2;
        CustomGridView CustomGridList1;
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            InitControl();
            if (!base.Page.IsPostBack) {
                Bind();
                QSDataDLL();
            }
            CustomGridList1.OnLoadData += new EventHandler(CustomGridList1_OnLoadData);
            Button btnSeach = (Button)FindControl("btnSeach");
            btnSeach.Click += new EventHandler(btnSeach_Click);
        }
        protected void btnSeach_Click(object sender, EventArgs e)
        {
            Bind();
        }

        protected void InitControl() {
            CustomGridList1 = (CustomGridView)FindControl("CustomGridList1");
            DropDownList1 = (DropDownList)FindControl("DropDownList1");
            DropDownList2 = (DropDownList)FindControl("DropDownList2");
            Calendar1 = (MPCalendar)FindControl("Calendar1");
            Calendar2 = (MPCalendar)FindControl("Calendar2");
        }
        protected void Bind() {
            DataTable dt = _EluZSDataProvider.GetXYTJ(Calendar1.Text, Calendar2.Text, DropDownList1.SelectedValue, DropDownList2.SelectedValue,userid);
            CustomGridList1.DataSource = dt;
            CustomGridList1.RecordCount = dt.Rows.Count;
            CustomGridList1.DataBind();
        }
        protected void CustomGridList1_OnLoadData(object sender, EventArgs e)
        {
            Bind();
        }
        protected void QSDataDLL()
        {
            //List<EluZSProvider.Params> _params = _EluZSDataProvider.GetParams("区属");
            //EluZSProvider.Params item = new EluZSProvider.Params();
            //_params.Insert(0, item);
            DataTable dt = _EluZSDataProvider.GetParamYB("区属", GetSqlWhere());
            DropDownList1.DataSource = dt;
            DropDownList1.DataValueField = "keyvalue";
            DropDownList1.DataTextField = "keyname";
            DropDownList1.DataBind();
            DropDownList1.Items.Insert(0, "");
            List<EluZSProvider.Params> _params1 = _EluZSDataProvider.GetParams("房屋用途");
            EluZSProvider.Params item1 = new EluZSProvider.Params();
            _params1.Insert(0, item1);
            DropDownList2.DataSource = _params1;
            DropDownList2.DataValueField = "keyname";
            DropDownList2.DataTextField = "keyname";
            DropDownList2.DataBind();
        }

        protected string GetSqlWhere()
        {
            string sqlWhere = string.Empty;
            if (_EluZSDataProvider.IsQZSBM(userid))
            {
                sqlWhere += @" and (Select tt.ROLENAME  From zs_USER_IN_ROLE t Join  zs_Role tt  On  t.roleid=tt.id
Where  t.userid Like '%" + userid + "%') Like '%'||keyname||'%' ";
            }
            return sqlWhere;
        }
    }
}


